# coding=utf-8
import csv
from pathlib import Path
import os

class LimitProcess():
    @classmethod
    def getLimitContent(cls,test_item,path = os.path.join(Path(__file__).parent,"Assets/Limits.csv")):
        perLineDic = {}
        with open(path,encoding = "utf-8-sig",mode = "r") as f:
            dictReader = csv.DictReader(f)
            for row in dictReader:
                test_item = "{}_{}".format(row["TestName"],row["ParameterName"])
                assert (not bool(perLineDic.get(test_item))),"The test name {} is repeated.".format(test_item)
                perLineDic[test_item] = {"units":row["units"],"upperLimit":row["upperLimit"],"lowerLimit":
                row["lowerLimit"],"relaxedUpperLimit":row["relaxedUpperLimit"],"relaxedLowerLimit":row["relaxedLowerLimit"],
                "Condition":row["Condition"]}
        return perLineDic[test_item]
if __name__ == "__main__":
    test_item = "Mogul_Left_Program_System_Zone7_Read_Mogul_Left_Program_Color_Read"
    print(LimitProcess.getLimitContent(test_item,path = os.path.join(Path(__file__).parent,"Assets/Limits.csv")))
